package com.hyq.market.utils;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by hl on 2017/6/29.
 */

public class ButtonStatusUtil implements TextWatcher {
    private Button button;
    private  TextView[] textViews;
    private int textCount=1;

    public static ButtonStatusUtil getInstance(Button button) {
        ButtonStatusUtil b=new ButtonStatusUtil();
        b.setButton(button);
        return b;
    }





    public ButtonStatusUtil setButton(Button button) {
        this.button = button;
        return this;
    }

    public ButtonStatusUtil setTextViews(TextView ...textViews) {
        this.textViews = textViews;
        return this;
    }

    public ButtonStatusUtil setTextCount(int textCount) {
        this.textCount = textCount;
        return this;
    }




    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        if (textViews!=null&&textViews.length>0){
            for (TextView textView : textViews) {
                if (TextUtils.isEmpty(textView.getText()))
                    return;
            }
        }
        if (s.length()>=textCount&&button!=null)
            button.setEnabled(true);
    }
}
